package com.jcl.core.security;

import com.alibaba.fastjson.JSON;
import com.jcl.core.security.entity.ResultEnum;
import com.jcl.core.security.utils.ResultUtil;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @ClassName RestAccessDeniedHandler
 * @Description 无权访问 -- 403
 * @Author yyliu
 * @Date 2018/12/18 11:20
 * @Version 1.0
 **/
public class RestAccessDeniedHandler implements AccessDeniedHandler {

    @Override
    public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException e) throws IOException {
        response.setHeader("Access-Control-Allow-Origin", "*");
        response.setStatus(403);
        ResultUtil.failure(response,
                ResultEnum.USER_NO_ACCESS.getCode(),ResultEnum.USER_NO_ACCESS.getMessage());

    }
}
